home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / rawstat / rawstat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-24  |  5.1 KB  |  204 lines

  1. /* 
  2.  * rawstat.c --
  3.  *
  4.  *    Print out kerel statitics in a raw format;
  5.  *    <Structure name>
  6.  *    <field> <value>
  7.  *    <field> <value>
  8.  *    <field> <value>
  9.  *
  10.  * Copyright (C) 1986 Regents of the University of California
  11.  * All rights reserved.
  12.  */
  13.  
  14. #ifndef lint
  15. static char rcsid[] = "$Header: /sprite/src/cmds/rawstat/RCS/rawstat.c,v 1.10 90/09/24 14:40:30 douglis Exp $ SPRITE (Berkeley)";
  16. #endif not lint
  17.  
  18. #include "sprite.h"
  19. #include "fs.h"
  20. #include "fsCmd.h"
  21. #include "stdio.h"
  22. #include "option.h"
  23. #include "vm.h"
  24. #include "sysStats.h"
  25. #include "kernel/vm.h"
  26. #include "kernel/fs.h"
  27. #include "kernel/fsStat.h"
  28. #include "kernel/sched.h"
  29. #include "kernel/procMigrate.h"
  30.  
  31. Boolean doAllFsStats = FALSE;
  32. Boolean doAllVmStats = FALSE;
  33. Boolean doAllRpcStats = FALSE;
  34. Boolean doAllProcStats = FALSE;
  35. Boolean doAllRecovStats = FALSE;
  36. Boolean doAllMigStats = FALSE;
  37. Boolean noIdle    = FALSE;
  38. Boolean zero = FALSE;
  39. Boolean all = FALSE;
  40.  
  41. Option optionArray[] = {
  42.     {OPT_TRUE, "fs", (Address)&doAllFsStats, "Print ALL file system stats"},
  43.     {OPT_TRUE, "vm", (Address)&doAllVmStats, "Print ALL vm stats"},
  44.     {OPT_TRUE, "rpc", (Address)&doAllRpcStats, "Print ALL rpc stats"},
  45.     {OPT_TRUE, "proc", (Address)&doAllProcStats, "Print ALL proc stats"},
  46.     {OPT_TRUE, "recov", (Address)&doAllRecovStats, "Print ALL recov stats"},
  47.     {OPT_TRUE, "mig", (Address)&doAllMigStats, "Print ALL mig stats"},
  48.     {OPT_TRUE, "noidle", (Address)&noIdle, "Don't print idle ticks info"},
  49.     {OPT_TRUE, "zero", (Address)&zero, "Print zero valued stats"},
  50.     {OPT_TRUE, "all", (Address)&all, "Print all stats"},
  51. };
  52. int numOptions = sizeof(optionArray) / sizeof(Option);
  53.  
  54. Fs_Stats fsStats;
  55. Vm_Stat    vmStats;
  56. Fs_TypeStats fsTypeStats;
  57.  
  58. main(argc, argv)
  59.     int argc;
  60.     char *argv[];
  61. {
  62.     int status = SUCCESS;
  63.     int virtualHost, physicalHost;
  64.  
  65.     argc = Opt_Parse(argc, argv, optionArray, numOptions);
  66.  
  67.     if (all) {
  68.     doAllFsStats = TRUE;
  69.     doAllVmStats = TRUE;
  70.     doAllRpcStats = TRUE;
  71.     doAllProcStats = TRUE;
  72.     doAllRecovStats = TRUE;
  73.     doAllMigStats = TRUE;
  74.     }
  75.  
  76.     system("echo RAWSTAT `hostname` `date`");
  77.  
  78.     if (!noIdle) {
  79.     PrintRawIdle();
  80.     }
  81.  
  82.     if (doAllFsStats) {
  83.     status = Fs_Command(FS_RETURN_STATS, sizeof(Fs_Stats), &fsStats);
  84.     if (status != SUCCESS) {
  85.         Stat_PrintMsg(status, "Fs_Command(FS_RETURN_STATS)");
  86.     } else if (fsStats.statsVersion == FS_STAT_VERSION) {
  87.         PrintRawFsCltName(&fsStats.cltName);
  88.         PrintRawFsSrvName(&fsStats.srvName);
  89.         PrintRawFsGen(&fsStats.gen);
  90.         PrintRawFsBlockCache(&fsStats.blockCache);
  91.         PrintRawFsAlloc(&fsStats.alloc);
  92.         PrintRawFsNameCache(&fsStats.nameCache);
  93.         PrintRawFsHandle(&fsStats.handle);
  94.         PrintRawFsPrefix(&fsStats.prefix);
  95.         PrintRawFsLookup(&fsStats.lookup);
  96.         PrintRawFsObject(&fsStats.object);
  97.         PrintRawFsRecovery(&fsStats.recovery);
  98.         PrintRawFsConsist(&fsStats.consist);
  99.         PrintRawFsWriteBack(&fsStats.writeBack);
  100.         PrintRawRemoteIO(&fsStats.rmtIO);
  101.         PrintRawFsMig(&fsStats.mig);
  102.     } else {
  103.         fprintf(stderr,
  104.             "Wrong version of Fs_Stats: kernel is %d, while ours is %d.\n",
  105.             fsStats.statsVersion, FS_STAT_VERSION);
  106.     }
  107.     }
  108.     if (doAllVmStats) {
  109.     int pageSize;
  110.     status = Vm_Cmd(VM_GET_STATS, &vmStats);
  111.     if (status != SUCCESS) {
  112.         Stat_PrintMsg(status, "Vm_Cmd failed");
  113.         exit(status);
  114.     }
  115.     Vm_PageSize(&pageSize);
  116.     PrintRawVmStat(&vmStats);
  117.     printf("\tpagesize %d\n", pageSize);
  118.     }
  119.     if (doAllRpcStats) {
  120.     PrintRawRpcCltStat();
  121.     PrintRawRpcSrvStat();
  122.     PrintSrvCount();
  123.     PrintCallCount();
  124.     }
  125.     if (doAllProcStats) {
  126.     PrintRawProcMigStat();
  127.     }
  128.     if (doAllMigStats) {
  129.     PrintRawMigStat();
  130.     }
  131.     if (doAllRecovStats) {
  132.     PrintRawRecovStat();
  133.     }
  134.     exit(0);
  135. }
  136.  
  137.  
  138. /*
  139.  *----------------------------------------------------------------------
  140.  *
  141.  * PrintRawIdle --
  142.  *
  143.  *    Prints the raw idle ticks of the machine.
  144.  *
  145.  * Results:
  146.  *    None.
  147.  *
  148.  * Side effects:
  149.  *    None.
  150.  *
  151.  *----------------------------------------------------------------------
  152.  */
  153.  
  154. PrintRawIdle()
  155. {
  156.     Sched_Instrument schedStats;
  157.     struct perProcessor *X = &schedStats.processor[0];
  158.     ReturnStatus status;
  159.  
  160.     status = Sys_Stats(SYS_SCHED_STATS, 0, &schedStats);
  161.     if (status != SUCCESS) {
  162.     Stat_PrintMsg(status, "Error in Sys_Stats");
  163.     exit(status);
  164.     }
  165.     printf("numContextSwitches %8u\n", X->numContextSwitches);
  166.     printf("numInvoluntarySwitches %8u\n", X->numInvoluntarySwitches);
  167.     printf("numFullCS      %8u\n", X->numFullCS);
  168.     printf("idleTime       %8d.%06d\n", X->idleTime.seconds,
  169.                         X->idleTime.microseconds);
  170.     printf("idleTicksLow   %8u\n", X->idleTicksLow);
  171.     printf("idleTicksOverflow %8u\n", X->idleTicksOverflow);
  172.     printf("idleTicksPerSecond %8u\n", X->idleTicksPerSecond);
  173.     printf("noInput %8d.%06d\n", schedStats.noUserInput.seconds,
  174.            schedStats.noUserInput.microseconds);
  175.     printf("\n");
  176.  
  177. }
  178.  
  179. /*
  180.  *----------------------------------------------------------------------
  181.  *
  182.  * ZeroPrint --
  183.  *
  184.  *    Prints a field if non-zero or if the global variable zero is set.
  185.  *
  186.  * Results:
  187.  *    None.
  188.  *
  189.  * Side effects:
  190.  *    None.
  191.  *
  192.  *----------------------------------------------------------------------
  193.  */
  194.  
  195. ZeroPrint(format, value)
  196.     char *format;
  197.     int value;
  198. {
  199.     if (zero || value != 0) {
  200.     printf(format, value);
  201.     }
  202. }
  203.  
  204.